# 打印菱形
def print_diamond(width):
    # 打印上半部分
    for i in range(width // 2 + 1):
        # 打印前导空格
        for j in range(width // 2 - i):
            print(" ", end="")
        # 打印星号

        for j in range(2 * i + 1):
            print("*", end="")
        print()  # 换行

    # 打印下半部分
    for i in range(width // 2 - 1, -1, -1):
        # 打印前导空格
        for j in range(width // 2 - i):
            print(" ", end="")
        # 打印星号
        for j in range(2 * i + 1):
            print("*", end="")
        print()  # 换行


# 调用函数打印宽度为 7 的菱形
print_diamond(7)

for n in range(100, 1000):
    i = n // 100  # 取百位
    j = n // 10 % 10  # 取十位
    k = n % 10  # 取个位
    if n == (i ** 3 + j ** 3 + k ** 3):
        print(n)



# 100以内质数
def is_prime(num):
    """判断一个数是否为质数"""
    if num <= 1:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True


# 找出 100 以内的所有质数
primes = [num for num in range(2, 100) if is_prime(num)]

# 打印结果
print(primes)
# 打印九九乘法表
for i in range(1, 10):
    for j in range(1, i + 1):
        print(f"{j} * {i} = {i * j}", end="\t")
    print()  # 换行


    # 斐波那契数列
    def fibonacci(n):
        if n <= 0:
            return []
        elif n == 1:
            return [0]
        elif n == 2:
            return [0, 1]

        fib = [0, 1]
        for i in range(2, n):
            fib.append(fib[-1] + fib[-2])
        return fib


    # 生成前 10 项斐波那契数列
    fib_sequence = fibonacci(10)
    print(fib_sequence)


    # 100以内完数
    def is_perfect_number(num):
        """判断一个数是否为完数"""
        if num < 1:
            return False

        divisors_sum = 0
        for i in range(1, num):
            if num % i == 0:
                divisors_sum += i

        return divisors_sum == num


    # 找出 100 以内的所有完数
    perfect_numbers = [num for num in range(1, 100) if is_perfect_number(num)]

    # 打印结果
    print(perfect_numbers)
